package com.onlyxiahui.common.action.description.util;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Collection;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Properties;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * Description <br>
 * Date 2020-01-08 16:37:53<br>
 * 
 * @author XiaHui [onlovexiahui@qq.com]<br>
 * @since 1.0.0
 */

public class ActionClassUtil {

	public static boolean isBean(Class<?> classType) {
		if (null != classType) {
			boolean isBean = !classType.isAnnotation()
					&& !classType.isArray()
					&& !classType.isEnum()
					&& !classType.isInterface()
					&& !isPrimitive(classType)
					&& !isBaseProperty(classType);

			return isBean;
		}
		return false;
	}

	public static boolean isPrimitive(Class<?> classType) {
		return null != classType
				&& ((classType.isPrimitive())
						|| (classType == Integer.class)
						|| (classType == int.class)
						|| (classType == Long.class)
						|| (classType == long.class)
						|| (classType == Float.class)
						|| (classType == float.class)
						|| (classType == Double.class)
						|| (classType == double.class)
						|| (classType == Byte.class)
						|| (classType == byte.class)
						|| (classType == Character.class)
						|| (classType == char.class)
						|| (classType == Boolean.class)
						|| (classType == boolean.class)
						|| (classType == Short.class)
						|| (classType == short.class));
	}

	/****************** primitive start ******************************/
	public static boolean isInteger(Class<?> classType) {
		return Integer.class.isAssignableFrom(classType)
				|| int.class.isAssignableFrom(classType)
				|| (Integer.class == classType)
				|| (int.class == classType);
	}

	public static boolean isLong(Class<?> classType) {
		return Long.class.isAssignableFrom(classType)
				|| long.class.isAssignableFrom(classType)
				|| (Long.class == classType)
				|| (long.class == classType);
	}

	public static boolean isFloat(Class<?> classType) {
		return Float.class.isAssignableFrom(classType)
				|| float.class.isAssignableFrom(classType)
				|| (Float.class == classType)
				|| (float.class == classType);
	}

	public static boolean isDouble(Class<?> classType) {
		return Double.class.isAssignableFrom(classType)
				|| double.class.isAssignableFrom(classType)
				|| (Double.class == classType)
				|| (double.class == classType);
	}

	public static boolean isByte(Class<?> classType) {
		return Byte.class.isAssignableFrom(classType)
				|| byte.class.isAssignableFrom(classType)
				|| (Byte.class == classType)
				|| (byte.class == classType);
	}

	public static boolean isShort(Class<?> classType) {
		return Short.class.isAssignableFrom(classType)
				|| short.class.isAssignableFrom(classType)
				|| (Short.class == classType)
				|| (short.class == classType);
	}

	public static boolean isCharacter(Class<?> classType) {
		return Character.class.isAssignableFrom(classType)
				|| char.class.isAssignableFrom(classType)
				|| (Character.class == classType)
				|| (char.class == classType);
	}

	public static boolean isBoolean(Class<?> classType) {
		return Boolean.class.isAssignableFrom(classType)
				|| boolean.class.isAssignableFrom(classType)
				|| Boolean.class == classType
				|| boolean.class == classType;
	}

	/****************** primitive end ******************************/

	public static boolean isBigInteger(Class<?> classType) {
		return BigInteger.class.isAssignableFrom(classType);
	}

	public static boolean isAtomicInteger(Class<?> classType) {
		return AtomicInteger.class.isAssignableFrom(classType);
	}

	public static boolean isBigDecimal(Class<?> classType) {
		return BigDecimal.class.isAssignableFrom(classType);
	}

	public static boolean isNumber(Class<?> classType) {
		return Number.class.isAssignableFrom(classType);
	}

	public static boolean isBaseProperty(Class<?> classType) {
		return Comparable.class.isAssignableFrom(classType);
	}

	public static boolean isArray(Class<?> classType) {
		return classType.isArray();
	}

	public static boolean isString(Class<?> classType) {
		return CharSequence.class.isAssignableFrom(classType);
	}

	public static boolean isCollection(Class<?> classType) {
		return Collection.class.isAssignableFrom(classType);
	}

	public static boolean isMap(Class<?> classType) {
		return Map.class.isAssignableFrom(classType);
	}

	public static boolean isBaseEntityMap(Class<?> classType) {
		return null != classType && Map.class.isAssignableFrom(classType)
				&& (classType == SortedMap.class
						|| classType == TreeMap.class
						|| classType == LinkedHashMap.class
						|| classType == HashMap.class
						|| classType == ConcurrentHashMap.class
						|| classType == Properties.class
						|| classType == Hashtable.class);
	}
}
